package com.zl.smartmall.library.listener;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

import com.zl.smartmall.library.po.MyAddress;
import com.zl.smartmall.library.util.Constants;
import com.zl.smartmall.library.util.CrashHandler;

/**
 * 维修项目数据请求监听类
 * 
 * @author 陈希然
 * 
 */
public abstract class MyAddressListener extends BaseListener {
	private static final String TAG = MyAddressListener.class.getSimpleName();

	@Override
	public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

		try {
			int status = response.getInt(Constants.REQ_STATUS);
			String msg = response.getString(Constants.REQ_MSG);
			CrashHandler.d(TAG, "我的小区服务器status = " + status);
			CrashHandler.d(TAG, "我的小区列表服务器msg = " + msg);
			CrashHandler.d(TAG, response.getJSONObject(Constants.REQ_RESULT).toString());
			switch (status) {
			case Constants.REQ_OK:
				JSONObject jsonObject = response.getJSONObject(Constants.REQ_RESULT);
				onResponseSuccess(headers,MyAddress.parse(jsonObject));
				break;

			case Constants.REQ_OFFLINE:
				onOffline();
				break;
				
			default:
				onResponseFailed();
			}

		} catch (JSONException e) {
			onFailure(statusCode, headers, e, new JSONObject());
		}
	}

	@Override
	public void onFailure(int statusCode, Header[] headers,
			Throwable throwable, JSONObject errorResponse) {
		// TODO Auto-generated method stub
		CrashHandler.e(throwable);
		onResponseFailed();
	}

	@Override
	public void onNoMoreData() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void onOffline() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 我的地址数据请求成功
	 */
	public abstract void onResponseSuccess(Header[] headers,MyAddress address);
	
}
